
export abstract class INativeHelper{
    private _callbackCount:number = 0;

    public abstract callWithReturnType(className:string, methodName:string, returnType:string | boolean | number, ...args):string | boolean | number;
    public call(className:string, methodName:string, ...args):void{
        this.callWithReturnType(className, methodName, null, ...args);
    }

    public registerCallback(caller:any, method:Function, times:number, ...args):string{
        if(caller == null || method == null){
            return "";
        }
        ++this._callbackCount;
        let callbackName = 'NativeHelper.callback' + this._callbackCount;
        window[callbackName] = ()=>{
            method.apply(caller, args);
            if(--times <= 0){
                window[callbackName] = null;
            }
        }
        return `window['${callbackName}']()`;
    }
}
